/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jifConsultarGrupo.java
 *a
 * Created on 19-oct-2010, 16:39:18
 */

package Suministros;
import administracion.delegate.GestionPedidosDelegate;
import administracion.helper.Listas;
import administracion.helper.MiTablePrint;
import administracion.helper.Utiles_MensajesDialogo;
import administracion.helper.Utiles_Tabla;
import administracion.helper.jPaginacion;
import com.jidesoft.hints.ListDataIntelliHints;
import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.ELProperty;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;
import suministros.ejb30.TO.GrupoSuministrosTO;
import suministros.ejb30.TO.SuministroTO;
import suministros.ejb30.TO.TipoTO;
/**
 *
 * @author Diana
 */
public class jifConsultarGrupo extends javax.swing.JInternalFrame implements Observer{
    private ListDataIntelliHints intelliHintsGrupo;
    GrupoSuministrosTO grupo;
    List<GrupoSuministrosTO> listaGrupos= new ArrayList<GrupoSuministrosTO>();
    private JTableBinding jTableBinding;
    List<TipoTO> listaTipos;
    private  jPaginacion panelPaginacion;
    /** Creates new form jifConsultarGrupo */
    public jifConsultarGrupo() {
        this.panelPaginacion = new jPaginacion(this,15);
        initComponents();
         try {
            cargaHintsIndependientes();
        } catch (Exception ex) {
            Logger.getLogger(jifConsultarSuministro.class.getName()).log(Level.SEVERE, null, ex);
        }
       llenarComboTipoSuministro();
       this.jPanel2.setVisible(false);

    }
     private void llenarComboTipoSuministro() {
        listaTipos = null;
        List listaTipos_cbo1 = this.cboBeanBindingTipo1.getLista();
        listaTipos_cbo1.clear();
        try
        {
          listaTipos = Listas.getTipo_porTabla("tipo_suministros");

          this.cboBeanBindingTipo1.setLista(listaTipos);
          this.bindingGroup.bind();
          this.jcbTipo.updateUI();
          this.jcbTipo.setSelectedIndex(-1);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener Tipos\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifRegistrarGrupoSuministros.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
     private void cargaHintsIndependientes() throws Exception {
    this.intelliHintsGrupo = new ListDataIntelliHints(this.jtfDescGrupo, Listas.getGrupospadre());
  }
    private void buscarGrupos()
  {
    this.grupo = null;
    GrupoSuministrosTO sumi;
    if (this.jtfCodGrupo.getText().trim().length() < 1) {

      try { sumi = (GrupoSuministrosTO)this.intelliHintsGrupo.getSelectedHint();
      } catch (NullPointerException ex) {
        sumi = null;
      }
    } else {
      sumi = Listas.getGrupoCodigo(this.jtfCodGrupo.getText().trim());
    }

    if (sumi == null) {
      Utiles_MensajesDialogo.mensajeError("El suministro no existe!");
      this.jtfDescGrupo.setText("");
      //this.jbtAceptar.setEnabled(false);
     } else {
      this.jtfDescGrupo.setText(sumi.toString());
      this.jtfCodGrupo.setText(sumi.getCodigo());
      //this.jbtAceptar.setEnabled(true);
      this.grupo = sumi;
    }
  }
    public void consultar(){
        try {
            if(this.jRadioButton3.isSelected())
            this.listaGrupos = GestionPedidosDelegate.getInstance().getListaGruposConsultar("", 1,this.panelPaginacion.getPagActual(),this.panelPaginacion.getPagTamano());
            if(this.jRadioButton1.isSelected())
            this.listaGrupos = GestionPedidosDelegate.getInstance().getListaGruposConsultar(this.jtfCodGrupo.getText(), 2,this.panelPaginacion.getPagActual(),this.panelPaginacion.getPagTamano());
            if(this.jRadioButton2.isSelected()){
                String t=((TipoTO)(this.jcbTipo.getSelectedItem())).getId_tabla_tipo().toString();
            this.listaGrupos = GestionPedidosDelegate.getInstance().getListaGruposConsultar(t, 3,this.panelPaginacion.getPagActual(),this.panelPaginacion.getPagTamano());
            }
            
        } catch (Exception ex) {
            Logger.getLogger(jifConsultarSuministro.class.getName()).log(Level.SEVERE, null, ex);
        }
        if(this.listaGrupos.isEmpty()){
            Utiles_MensajesDialogo.mensajeAlerta("No se han encontrado suministros");
        }
        
    }
    public int consultarTamaño(){
        int tamaño=0;

        try {
            if(this.jRadioButton3.isSelected())
            tamaño=GestionPedidosDelegate.getInstance().getListaGruposConsultarTamaño("", 1);
            if(this.jRadioButton1.isSelected())
            tamaño=GestionPedidosDelegate.getInstance().getListaGruposConsultarTamaño(this.jtfCodGrupo.getText(), 2);
            if(this.jRadioButton2.isSelected()){
            String t=((TipoTO)(this.jcbTipo.getSelectedItem())).getId_tabla_tipo().toString();
            tamaño= GestionPedidosDelegate.getInstance().getListaGruposConsultarTamaño(t, 3);
            }

        } catch (Exception ex) {
            Logger.getLogger(jifConsultarSuministro.class.getName()).log(Level.SEVERE, null, ex);
        }
  
        return tamaño;

    }
    public void actualizarTabla(){
    this.bindingGroup = new BindingGroup();
    this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, this.listaGrupos, this.jTable1);

    JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${codigo}"));

    columnBinding0.setColumnName("Codigo");
    columnBinding0.setColumnClass(String.class);
    columnBinding0.setEditable(false);

    JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${descripcion}"));

    columnBinding1.setColumnName("Descripcion");
    columnBinding1.setColumnClass(String.class);
    columnBinding1.setEditable(false);

    JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${cod_antecesor}"));

    columnBinding2.setColumnName("GrupoAntecesor");
    columnBinding2.setColumnClass(String.class);
    columnBinding2.setEditable(false);

    JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding.addColumnBinding(ELProperty.create("${descTipo}"));

    columnBinding3.setColumnName("TipoSuministro");
    columnBinding3.setColumnClass(String.class);
    columnBinding3.setEditable(false);



    this.bindingGroup.addBinding(this.jTableBinding);
    this.bindingGroup.bind();
     try {
         int[] porcentajes= {10,50,20,20};
          Utiles_Tabla.definirAnchoColumnasJTable(this.jTable1, porcentajes);
          // MiTablePrint.autoSizeTableColumns(jtDetalleSuministro);
        } catch (Exception ex) {
            Logger.getLogger(jifConsultarSuministro.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
       private void buscar(){
       try
        {
           int num_ordenes_encontradas =consultarTamaño();
           panelPaginacion.setTotalResultados(num_ordenes_encontradas);
        }
        catch (Exception e) {
            Utiles_MensajesDialogo.mensajeError(e.getMessage());
        }
      }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        buttonGroup1 = new javax.swing.ButtonGroup();
        cboBeanBindingTipo1 = new administracion.BeanBinding.CboBeanBindingTipo();
        jPanel1 = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtfCodGrupo = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtfDescGrupo = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jcbTipo = new javax.swing.JComboBox();
        jbtBuscar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jbtCancelar = new javax.swing.JButton();
        jbtImprimir1 = new javax.swing.JButton();

        setTitle("CONSULTAR GRUPO DE SUMINISTROS");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "TIPO DE CONSULTA", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), new java.awt.Color(0, 0, 255))); // NOI18N

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setText("GRUPOS POR GRUPO ANTECESOR");
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        buttonGroup1.add(jRadioButton3);
        jRadioButton3.setSelected(true);
        jRadioButton3.setText("TODOS LOS GRUPOS");
        jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton3ActionPerformed(evt);
            }
        });

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText("GRUPO POR TIPO DE SUMINISTRO");
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jRadioButton3)
                    .addComponent(jRadioButton1)
                    .addComponent(jRadioButton2))
                .addContainerGap(305, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jRadioButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jRadioButton2))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "PARAMETROS DE BUSQUEDA", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), new java.awt.Color(0, 0, 255))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel1.setText("CODIGO");

        jtfCodGrupo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfCodGrupoActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel2.setText("DESC GRUPO");

        jtfDescGrupo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfDescGrupoActionPerformed(evt);
            }
        });
        jtfDescGrupo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfDescGrupoKeyPressed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel3.setText("TIPO SUMINISTRO:");

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingTipo1, eLProperty, jcbTipo);
        bindingGroup.addBinding(jComboBoxBinding);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(25, 25, 25)
                        .addComponent(jtfCodGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfDescGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(7, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(4, 4, 4)
                        .addComponent(jcbTipo, 0, 318, Short.MAX_VALUE)
                        .addGap(70, 70, 70))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtfCodGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jtfDescGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jLabel3))
                    .addComponent(jcbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jbtBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/find.png"))); // NOI18N
        jbtBuscar.setText("Buscar");
        jbtBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtBuscarActionPerformed(evt);
            }
        });
        jbtBuscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbtBuscarKeyPressed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "RESULTADOS ENCONTRADOS", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), new java.awt.Color(0, 0, 255))); // NOI18N
        jPanel3.setLayout(new java.awt.BorderLayout());
        jPanel3.add(panelPaginacion,BorderLayout.NORTH);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Codigo", "Descripcion", "Grupo Antecesor", "TipoSumi"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jbtCancelar.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jbtCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_cancel.png"))); // NOI18N
        jbtCancelar.setMnemonic('C');
        jbtCancelar.setText("CERRAR");
        jbtCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCancelarActionPerformed(evt);
            }
        });

        jbtImprimir1.setFont(new java.awt.Font("Arial", 1, 12));
        jbtImprimir1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/document_print.png"))); // NOI18N
        jbtImprimir1.setText("IMPRIMIR");
        jbtImprimir1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtImprimir1ActionPerformed(evt);
            }
        });
        jbtImprimir1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbtImprimir1KeyPressed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, 0, 516, Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jbtBuscar, javax.swing.GroupLayout.Alignment.LEADING))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jbtImprimir1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtCancelar)
                        .addGap(126, 126, 126))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtBuscar)
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtCancelar)
                    .addComponent(jbtImprimir1)))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
        if(this.jRadioButton1.isSelected()){
            this.jPanel2.setVisible(true);
            this.jtfCodGrupo.setVisible(true);
            this.jtfDescGrupo.setVisible(true);
            this.jcbTipo.setVisible(false);
            this.jLabel3.setVisible(false);
            this.jLabel1.setVisible(true);
            this.jLabel2.setVisible(true);
            this.listaGrupos.clear();
            this.actualizarTabla();
            this.jtfCodGrupo.setText("");
            this.jtfDescGrupo.setText("");
            this.jcbTipo.setSelectedIndex(-1);
            this.pack();
        }
}//GEN-LAST:event_jRadioButton1ActionPerformed

    private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton3ActionPerformed
        if(this.jRadioButton3.isSelected()){
            this.jPanel2.setVisible(false);
            this.listaGrupos.clear();
            this.jtfCodGrupo.setText("");
            this.jtfDescGrupo.setText("");
            this.actualizarTabla();
            this.pack();
        }
}//GEN-LAST:event_jRadioButton3ActionPerformed

    private void jtfCodGrupoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfCodGrupoActionPerformed
        if (this.jtfCodGrupo.getText().trim().length() < 1)
            this.jtfDescGrupo.requestFocus();
        else
            this.buscarGrupos();
}//GEN-LAST:event_jtfCodGrupoActionPerformed

    private void jtfDescGrupoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfDescGrupoActionPerformed
        this.buscarGrupos();
}//GEN-LAST:event_jtfDescGrupoActionPerformed

    private void jtfDescGrupoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfDescGrupoKeyPressed
        if (this.jtfCodGrupo.getText().trim().length() > 0){
            this.jtfCodGrupo.setText("");
        }
}//GEN-LAST:event_jtfDescGrupoKeyPressed

    private void jbtBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtBuscarActionPerformed
        buscar();
    }//GEN-LAST:event_jbtBuscarActionPerformed

    private void jbtBuscarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbtBuscarKeyPressed
        if(KeyEvent.VK_ENTER == evt.getKeyCode() ||KeyEvent.VK_TAB == evt.getKeyCode()  ){
            this.jbtBuscar.doClick();
        }
}//GEN-LAST:event_jbtBuscarKeyPressed

    private void jbtCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtCancelarActionPerformed
        int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro de salir?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){
            this.dispose();
        }
}//GEN-LAST:event_jbtCancelarActionPerformed

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
      if(this.jRadioButton2.isSelected()){
            this.jPanel2.setVisible(true);
            this.jtfCodGrupo.setVisible(false);
            this.jtfDescGrupo.setVisible(false);
            this.jLabel1.setVisible(false);
            this.jLabel2.setVisible(false);
            this.jcbTipo.setVisible(true);
            this.jLabel3.setVisible(true);
            this.listaGrupos.clear();
            this.actualizarTabla();
            this.jtfCodGrupo.setText("");
            this.jtfDescGrupo.setText("");
            this.jcbTipo.setSelectedIndex(-1);
            this.pack();
        }
    }//GEN-LAST:event_jRadioButton2ActionPerformed

    private void jbtImprimir1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtImprimir1ActionPerformed

        MiTablePrint pp = new MiTablePrint(this.jTable1, "GRUPOS DE SUMINISTROS", "LISTADO DE GRUPO DE SUMINISTROS");
        pp.showPrintPreview();
}//GEN-LAST:event_jbtImprimir1ActionPerformed

    private void jbtImprimir1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbtImprimir1KeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbtImprimir1.doClick();
        }
}//GEN-LAST:event_jbtImprimir1KeyPressed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private administracion.BeanBinding.CboBeanBindingTipo cboBeanBindingTipo1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JButton jbtBuscar;
    private javax.swing.JButton jbtCancelar;
    private javax.swing.JButton jbtImprimir1;
    private javax.swing.JComboBox jcbTipo;
    private javax.swing.JTextField jtfCodGrupo;
    private javax.swing.JTextField jtfDescGrupo;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    public void update(Observable o, Object arg) {
       this.consultar();
       actualizarTabla();
    }

}
